package com.iflytek.universitymanagement.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytek.universitymanagement.domain.WeakCourse;
import com.iflytek.universitymanagement.domain.WeakCourseDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WeakCourseMapper extends BaseMapper<WeakCourse> {
    @Select("SELECT " +
            "wc.weak_course_id AS weakCourseId, " +
            "s.name AS studentName, " +
            "c.course_name AS courseName, " +
            "ss.score AS score, " +
            "ss.semester AS semester, " +
            "ss.progress AS progress " +
            "FROM weak_course wc " +
            "LEFT JOIN student_score ss ON wc.score_id = ss.score_id " +
            "LEFT JOIN student s ON ss.student_id = s.student_id " +
            "LEFT JOIN course c ON ss.course_id = c.course_id " +
            "WHERE ss.score < 60")
    List<WeakCourseDTO> getAllWeakCoursesWithNames();


    @Select("SELECT " +
            "wc.weak_course_id AS weakCourseId, " +
            "s.name AS studentName, " +
            "ss.student_id AS studentId,"+
            "ss.course_id AS courseId,"+
            "c.course_name AS courseName, " +
            "ss.score " +
            "FROM weak_course wc " +
            "LEFT JOIN student_score ss ON wc.score_id = ss.score_id " +
            "LEFT JOIN student s ON ss.student_id = s.student_id " +
            "LEFT JOIN course c ON ss.course_id = c.course_id " +
            "WHERE ss.score < 60 ${ew.customSqlSegment}")
    <T> IPage<WeakCourseDTO> selectPage(Page<T> tPage, @Param("ew") QueryWrapper<WeakCourseDTO> queryWrapper);



}
